import $service from '../../../../service.js';
var doctor_id; //医生id
var hospital_id = "1";
var log_id;
Page({
    data: { //遍历的数据
        active: true,
        guidance_name: '',
        carouselActivityList: [],
        isdetalis:false,
        guidance_nameText:''
    },
    onLoad(e) { //拿到上一页传过来的参数
        log_id =e.log_id
    },
    onShow() { //加载页面
    doctor_id = $service.getUserLocalStorage().doctor_id;
    if (!$service.isUndefinedAndEmpty($service.getUserLocalStorage().hospital_id)) {
        hospital_id = $service.getUserLocalStorage().hospital_id
    }
        this.doctorSide_personal_inquiry_getHealthGuidanceTemplate()
    },
    doctorSide_personal_inquiry_getHealthGuidanceTemplate: function() {
        if(this.data.active){
            var doctorid =0
        }else{
            var doctorid = doctor_id
        }
        var jsonData = {
            "doctor_id": doctorid,
            "guidance_name": this.data.guidance_name,
            "hospital_id": hospital_id
        }

        var jsonAjax = {
            "url": "doctorSide_personal_inquiry_getHealthGuidanceTemplate.do",
            "jsonData": jsonData,
        }
        $service.getAjaxData(jsonAjax, this.doctorSide_personal_inquiry_getHealthGuidanceTemplate_back);
    },
    doctorSide_personal_inquiry_getHealthGuidanceTemplate_back: function(jsonBack) {
        var data = $service.strToJson(jsonBack.data).data;

        console.log(jsonBack.data)
        this.setData({
            carouselActivityList: data.healthGuidanceTemplateList
        })

    },
    tabclick(e) { //方法
        console.log(e)
        this.data.active = !this.data.active
        this.setData({
            active: this.data.active
        })
        this.doctorSide_personal_inquiry_getHealthGuidanceTemplate()
    },

    watchmodel(e) { //输入框监听
        this.setData({
            guidance_name: e.detail.value
        })
        this.doctorSide_personal_inquiry_getHealthGuidanceTemplate()
    },
    gotopage(e) {//1删除模板 2查看模板 3引用意见单 4关闭弹窗
        var this_= this
        var index = e.currentTarget.dataset.index;
        var num = e.currentTarget.dataset.num;
        if(index == 1){
            wx.showModal({
                title: '温馨提示',
                content: '确定要删除此意见单？',
                success(res) {
                    if (res.confirm) {
                        var jsonData ={
                            "guidance_id" : this_.data.carouselActivityList[num].guidance_id,
                        }
                        var jsonAjax = {
                            "url": "doctorSide_personal_inquiry_deleteHealthGuidance.do",
                            "jsonData": jsonData,
                        }
                        $service.getAjaxData(jsonAjax, function(jsonObj) {
                            $service.showToast('删除成功')
                            this_.doctorSide_personal_inquiry_getHealthGuidanceTemplate()
                        });
                    }
                }
            }) 
        }else if(index == 2){
            this.setData({
                isdetalis:true,
                guidance_nameText:this_.data.carouselActivityList[num].guidance_content
            })
        }else if(index == 3){
            var Map = this_.data.carouselActivityList[num]
            $service.openPage('index_write_advice/index_write_advice?log_id=' + log_id +'&Map=' + $service.jsonToStr(Map))
        }else if(index == 4){
           this.setData({
               isdetalis:false
           })
        }
    },

})